home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-25 | 3.6 KB | 103 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // Backwards [Audio].c - Backwards audio filter
- //
- // Written by Randy Ubillos and Bryan K. "Beaker" Ressler.
- //
- // Copyright ⌐ 1993-96, Adobe Systems Incorporated, all rights reserved worldwide.
- //
- // Version 1.00 10/20/93 Original version.
- // Version 1.01 9/12/94 Updated for 4.0.
- // Version 1.02 10/6/95 Updated for 4.2 and CW7.
- //
- //========================================================================================
-
- //========================================================================================
- // Includes - use precompiled headers if compiling with CodeWarrior.
- //========================================================================================
- #ifdef __MWERKS__
- #ifdef powerc
- #include "PremierePPC"
- #else
- #include "Premiere68k"
- #endif
- #else
- #include "Premiere.h"
- #endif
-
- //========================================================================================
- // Perform the effect
- //========================================================================================
- pascal short main (short selector, AudioFilter theData)
- {
- short result = 0, flags;
- unsigned char *dest, *buff; // Byte-sized pointers
- unsigned short *wDest, *wBuff; // Word-sized pointers
- unsigned long *lDest, *lBuff; // Long-sized pointers
- long count, i, sample;
- char err;
-
- // Act according to the selector
- switch (selector) {
- case fsExecute:
- // Cache up some values into local storage
- flags = (*theData)->flags;
- dest = (unsigned char *)(*theData)->destination;
- count = (*theData)->samplecount;
-
- // Calculate location from which we should retrieve samples
- sample = (*theData)->totalsamples - count - (*theData)->samplenum;
-
- // Is it okay to call back for samples?
- if ((*theData)->callBack) {
- // We're in a situation where we can call back to get audio from another
- // point in time via the callBack parameter of theData. So, make some
- // space for the samples we're about to receive.
- if (buff = (unsigned char *)NewPtr(count)) {
- // Use the callback to retrieve the sound data for the sample offset
- // we calculated above.
- err = ((*theData)->callBack)(sample, count, (Ptr)buff,
- (*theData)->privateData);
-
- if (!err) {
- // We succeeded in getting a buffer-full of samples from the
- // "opposite" point in time. The samples in this buffer are,
- // however, not yet backwards. So, reverse the sample order
- // while copying the samples into the destination buffer.
-
- if ((flags & ga16Bit) && (flags & gaStereo)) {
- // 16-bit stereo (move a long at a time)
- lDest = (unsigned long *)dest;
- lBuff = (unsigned long *)buff;
- count >>= 2;
- for (i = 0; i < count; i++)
- lDest[i] = lBuff[count - i - 1];
- } else if (flags & (ga16Bit + gaStereo)) {
- // 16-bit eor stereo (move a word at a time)
- wDest = (unsigned short *)dest;
- wBuff = (unsigned short *)buff;
- count >>= 1;
- for (i = 0; i < count; i++)
- wDest[i] = wBuff[count - i - 1];
- } else {
- // 8-bit mono (move a byte at a time)
- for (i = 0; i < count; i++)
- dest[i] = buff[count - i - 1];
- }
- }
-
- // Lose our temporary buffer
- DisposPtr((Ptr)buff);
- }
- } else {
- // For whatever reason, callbacks to get sound from other points in time
- // are not allowed right now. So, just punt and copy the samples for the
- // current point in time to the destination buffer.
- BlockMove((*theData)->source, dest, count);
- }
- break;
- }
- return(result);
- }
-
-